﻿using dotnet_ef_admin.Src.Services;
using dotnet_ef_admin.Src.Utilities;

namespace dotnet_ef_admin.Src.Extensions;

public static class ServiceExtensions {
    public static IServiceCollection AddMyServices(this IServiceCollection services, IConfiguration configuration) {
        // 系统管理
        services.AddScoped<IUserService, UserService>();
        services.AddScoped<IRoleService, RoleService>();
        services.AddScoped<IDeptService, DeptService>();
        services.AddScoped<IDictService, DictService>();
        services.AddScoped<IMenuService, MenuService>();

        // 授权
        services.AddScoped<IAuthService, AuthService>();

        // 工具服务
        // 获取JWT密钥
        var jwtKey = configuration["Jwt:Key"];
        if (string.IsNullOrEmpty(jwtKey))
            throw new InvalidOperationException("配置错误:没有在设置中配置JWT密钥。");
        services.AddScoped(provider => new JwtService(jwtKey));

        return services;
    }
}